#!/usr/bin/env python
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from google.appengine.dist import use_library
use_library('django', '1.2')

import wsgiref.handlers
from google.appengine.ext import webapp
import logging

from model import StudentM
from model import LectureM
from model import PostClassM

class ClassStarterHandler(webapp.RequestHandler):
    
    def get(self):
        lectureKey=self.request.get('lectureKey')
        
        if lectureKey:
#            logging.debug("\n\n\nStudentVoteDeleteHandler, lectureKey: "+lectureKey+"\n\n\n")
            StudentM.deleteOldStudentVotes(lectureKey)
            
            lecture=LectureM.getLectureByKey(lectureKey)
            PostClassM.addPostClass(lecture)
        
def main():
    logging.getLogger().setLevel(logging.DEBUG)
    app = webapp.WSGIApplication([
        (r'.*', ClassStarterHandler)], debug=True)
    wsgiref.handlers.CGIHandler().run(app)

if __name__ == "__main__":
    main()